package org.streets.workflow.engine.task;

import org.streets.workflow.engine.ITaskInstance;
import org.streets.workflow.engine.WorkflowEngine;
import org.streets.workflow.engine.WorkflowException;


/**
 *
 */
public class DefaultSubflowTaskCompletionEvaluator implements ITaskEvaluator{

    /* (non-Javadoc)
     * @see org.fireflow.engine.taskinstance.ITaskInstanceCompletionEvaluator#taskInstanceCanBeCompleted(org.fireflow.engine.IWorkflowSession, org.fireflow.engine.RuntimeContext, org.fireflow.engine.IProcessInstance, org.fireflow.engine.ITaskInstance)
     */
    public boolean eval(WorkflowEngine currentSession, ITaskInstance taskInstance) throws WorkflowException {
        //系统默认每个子流程仅创建一个实例，所以当子流程实例完成后，SubflowTaskInstance都可以被completed
        //所以，应该直接返回true;
        return true;

        //如果系统动态创建了多个并发子流程实例，则需要检查是否存在活动的子流程实例，如果存在则返回false，否则返回true。
        //可以用下面的代码实现
//        IPersistenceService persistenceService = runtimeContext.getPersistenceService();
//        Integer count = persistenceService.getAliveProcessInstanceCountForParentTaskInstance(taskInstance.getId());
//        if (count>0){
//            return false;
//        }else{
//            return true;
//        }
    }
}
